package com.mjh.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mjh.mapper.WChxhKscjDtMapper;
import com.mjh.pojo.WChxhKscjDt;
import com.mjh.service.IWChxhKscjDtService;
import com.mjh.service.impl.WChxhKscjDtServiceImpl;
import com.mjh.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.HashMap;

/**
 *
 * 考试成绩 前端控制器
 *
 *
 * @author MJH
 * @since 2021-12-03
 */
@RestController
@RequestMapping("/score")
public class WChxhKscjDtController {

    @Autowired
    private WChxhKscjDtServiceImpl wChxhKscjDtService;

    @Autowired
    private IWChxhKscjDtService iwChxhKscjDtService;

    @Autowired
    private HttpServletRequest request;
    /**
     * 考试成绩
     * @param kscjDts
     */
    @PostMapping("/scoreadd")
    public void  insertReslut(@RequestBody WChxhKscjDt [] kscjDts){
        wChxhKscjDtService.saveBatch(Arrays.asList(kscjDts));
    }

    /**
     * 学习培训经历批量或单一删除
     * @param id
     */
    @GetMapping("/scoredle")
    public void scoredle( Integer [] id){
       iwChxhKscjDtService.removeByIds(Arrays.asList(id));
    }

    /**
     * 学习培训经理分页查询
     * @param currentPage 当前页码
     * @param pageSize    每页数量
     * @return
     */
    @GetMapping("/scoreslt")
    public ResponseEntity<Object> scoreslt(@RequestParam(defaultValue = "1") Integer currentPage,
                                           @RequestParam(defaultValue = "10")  Integer pageSize){
        Page<WChxhKscjDt> page = new Page<>(currentPage,pageSize);
        Integer userId = (Integer) JwtUtil.getPayload(request, "userId");
        Page<WChxhKscjDt> wtzxPage = iwChxhKscjDtService.scoreslt(page,userId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",wtzxPage.getTotal());
        map.put("currentPage",wtzxPage.getCurrent());
        map.put("list",wtzxPage.getRecords());
        return ResponseEntity.ok(map);
    }
}
